package dac.web.controller.system;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

//import dac.account.domain.Account;
//import dac.account.service.IAccountService;
import dac.common.core.controller.BaseController;
import dac.common.core.domain.AjaxResult;
import dac.common.core.domain.entity.SysUser;
import dac.common.core.domain.model.RegisterBody;
import dac.common.utils.StringUtils;
import dac.framework.web.service.SysRegisterService;
import dac.system.service.ISysConfigService;
import dac.system.service.ISysUserService;

/**
 * 注册验证
 * 
 * @author dac
 */
@RestController
public class SysRegisterController extends BaseController
{
    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private ISysConfigService configService;
//    @Autowired
//    private IAccountService accountService;
    @Autowired
    private ISysUserService userService;
    
    

    @PostMapping("/register")
    public AjaxResult register(@RequestBody RegisterBody user)
    {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
        {
            return error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        boolean flag = StringUtils.isEmpty(msg);
//		if(flag) {
//			SysUser userInfo = userService.selectUserByUserName(user.getUsername());
//			Account account = new Account();
//			account.setAccountNumber("Account"+userInfo.getUserId());
//			account.setUserId(userInfo.getUserId());
//			account.setBalance(new BigDecimal(0));
//			account.setStatus("0");
//			account.setRechargeMark("Y");
//			account.setConsumeMark("Y");
//			account.setBlockedBalance(new BigDecimal(0));
//			account.setCashBalance(new BigDecimal(0));
//			accountService.insertAccount(account);
//        }
        return flag ? success() : error(msg);
    }
}
